// module.exports = {}
//以下操作可以有智能提示
// 增加智能类型提示的小技巧，配置完成后将下一行注释掉即可
// import webpack from "webpack";

const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const {VueLoaderPlugin} = require('vue-loader')


/**
 * @type {webpack.Configuration}
 * 
 */
const config = {
  // mode: env.production ? 'production': 'development',
  entry: "./src/main.js",
  output: {
    filename: "bundle.js",
    path: path.join(__dirname, "dist")
  },
  optimization: { //tree-shaking
    usedExports: true,  //模块只导出被使用的成员
    minimize: true      //压缩输出结果
  },
  devServer: {
    hot: true // 开启HMR热更新，同时需要将webpack模块导入，并在插件处调用new webpack.HotModuleReplacementPlugin()
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        use: 'vue-loader'
      },
      {
        test: /\.css$/,
        use: [MiniCssExtractPlugin.loader, 'css-loader']
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './public/index.html'
    }),
    new MiniCssExtractPlugin(),
    new VueLoaderPlugin(),
    new webpack.HotModuleReplacementPlugin()
  ]
}

module.exports = config